package xyz.zdsoft.project_group_manage_module.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zdsoft.common.utils.Result;
import xyz.zdsoft.project_group_manage_module.service.DeleteTeamGchService;
import javax.annotation.Resource;

@RestController
@Api(tags = "项目组管理")
public class AdminDeleteTeamController {
    @Resource
    private DeleteTeamGchService deleteTeamGchService;
    @ApiImplicitParam(name = "teamId",value = "项目组id",example = "1",required = true)
    @ApiOperation("删除项目组")
    @PostMapping("/DeleteTeam")
    public Result deleteTeam(Long teamId){
        if (deleteTeamGchService.deleteTeam(teamId)>0){
            deleteTeamGchService.deleteTeamAndStudent(teamId);// 将该组所有成员逻辑删除
            return Result.ok().message("删除成功");
        }
        else return Result.error().message("删除失败");
    }
    @ApiImplicitParam(name = "studentIds",value ="学生id,若有多个则用','隔开",example = "1",required = true)
    @ApiOperation("删除项目组内成员(可批量删除)")
    @PostMapping("/DeleteStudentInTeam")
    public Result deleteStudentInTeam(Long[] studentIds){
        Integer sum= 0;
        for (Long studentId:studentIds){
            if (deleteTeamGchService.deleteStudentInTeam(studentId)>0){
                sum++;
            }
            else return Result.error().message("删除失败");
        }
        return Result.ok().message("删除成功!共删除了"+sum+"条记录");
    }

}
